package com.dnjn.happiness.biz.controller.common;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.biz.domain.CommunicateTags;
import com.dnjn.happiness.biz.domain.vo.CommunicateTagsVO;
import com.dnjn.happiness.biz.service.ICommunicateService;
import com.dnjn.happiness.biz.service.ICommunicateTagsService;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.annotation.RequiresPermissions;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;
import java.util.List;

/**
 * 沟通维度Controller
 *
 * @author happiness
 * @date 2024-04-01
 */

public class CommonCommunicateTagsController extends BaseController {
    @Autowired
    protected ICommunicateTagsService communicateTagsService;

    @Autowired
    private ICommunicateService communicateService;

    /**
     * 查询所有沟通维度列表
     */
    @Log(title = "沟通维度", businessType = BusinessType.LIST)
    @RequiresPermissions("@ss.hasAnyPermi('biz:CommunicateTags:list,ignore:CommunicateTags:list')")
    @PostMapping("/listAll")
    public AjaxResult listAll() {
        List<CommunicateTags> list = communicateTagsService.listAll();
        return success(list);
    }

    /**
     * 查询沟通维度列表
     */
    @Log(title = "沟通维度", businessType = BusinessType.LIST)
    @RequiresPermissions("@ss.hasAnyPermi('biz:CommunicateTags:list,ignore:CommunicateTags:list')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody CommunicateTagsVO vo, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        CommunicateTags communicateTags = new CommunicateTags();
        BeanUtils.copyPropsIgnoreNull(vo, communicateTags);
        Page page = Page.of(current, size);
        Page<CommunicateTags> list = communicateTagsService.page(page, Wrappers.query(communicateTags));
        return success(list);
    }

    /**
     * 获取沟通维度详细信息
     */
    @Log(title = "沟通维度", businessType = BusinessType.SELECT)
    @RequiresPermissions("@ss.hasAnyPermi('biz:CommunicateTags:query,ignore:CommunicateTags:query')")
    @GetMapping(value = "/{communicateTagsId}")
    public AjaxResult get(@PathVariable("communicateTagsId") Long communicateTagsId) {
        return success(communicateTagsService.getById(communicateTagsId));
    }

    /**
     * 新增沟通维度
     */
    @Log(title = "沟通维度", businessType = BusinessType.INSERT)
    @RequiresPermissions("@ss.hasAnyPermi('biz:CommunicateTags:add,ignore:CommunicateTags:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CommunicateTagsVO vo) {
        CommunicateTags communicateTags = new CommunicateTags();
        BeanUtils.copyPropsIgnoreNull(vo, communicateTags);

        communicateTags.setCreateBy(SecurityUtils.getUsername());
        return toAjax(communicateTagsService.save(communicateTags));
    }

    /**
     * 修改沟通维度
     */
    @Log(title = "沟通维度", businessType = BusinessType.UPDATE)
    @RequiresPermissions("@ss.hasAnyPermi('biz:CommunicateTags:edit,ignore:CommunicateTags:edit')")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody CommunicateTagsVO vo) {
        CommunicateTags communicateTags = new CommunicateTags();
        BeanUtils.copyPropsIgnoreNull(vo, communicateTags);
        return toAjax(communicateTagsService.updateById(communicateTags));
    }

    /**
     * 删除沟通维度
     */
    @Log(title = "沟通维度", businessType = BusinessType.DELETE)
    @RequiresPermissions("@ss.hasAnyPermi('biz:CommunicateTags:remove,ignore:CommunicateTags:remove')")
    @DeleteMapping("/{communicateTagsIds}")
    public AjaxResult remove(@PathVariable Long[] communicateTagsIds) {
        return toAjax(communicateTagsService.removeBatchByIds(Arrays.asList(communicateTagsIds)));
    }

}
